<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Api_favorite_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}

	function count_favorite_by_user_id_item_type($user_id=0,$item_type=1000){
		$this->db->select('favorite_id');
		$this->db->from('user_favorites');
		$this->db->where('user_id',$user_id);
		if($item_type<>1000){
			$this->db->where('item_type',$item_type);
		}
		
		$total=$this->db->count_all_results();
		return $total;
	}

	function get_favorite_by_user_id($page=0,$limit=4,$user_id=0,$ord='desc')
	{
		$start = $page*$limit;
		$this->db->select('*');
		$this->db->from('user_favorites');
		if($user_id>0){
			$this->db->where('user_id',$user_id);
		}
		$this->db->order_by('favorite_time',$ord);	
		$this->db->limit($limit,$start);
		$query = $this->db->get();
		if($query->num_rows() > 0){
			return $query->result_array();
		}
	}
}